home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / language / vietnamese.el.z / vietnamese.el
Encoding:
Text File  |  1998-05-21  |  15.3 KB  |  379 lines

  1. ;;; vietnamese.el --- Support for Vietnamese
  2.  
  3. ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
  4. ;; Licensed to the Free Software Foundation.
  5. ;; Copyright (C) 1997 MORIOKA Tomohiko
  6.  
  7. ;; Keywords: multilingual, Vietnamese
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  23. ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  24. ;; 02111-1307, USA.
  25.  
  26. ;;; Commentary:
  27.  
  28. ;; For Vietnames, the character sets VISCII and VSCII are supported.
  29.  
  30. ;;; Code:
  31.  
  32. (eval-when-compile
  33.  
  34. (defvar viet-viscii-decode-table
  35.   [;; VISCII is a full 8-bit code.
  36.    0 1 ?,2F(B 3 4 ?,2G(B ?,2g(B 7 8 9 10 11 12 13 14 15
  37.    16 17 18 19 ?,2V(B 21 22 23 24 ?,2[(B 26 27 28 29 ?,2\(B 31
  38.    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  39.    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  40.    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  41.    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  42.    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  43.    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 
  44.    ?,2U(B ?,2!(B ?,2"(B ?,2#(B ?,2$(B ?,2%(B ?,2&(B ?,2'(B ?,2((B ?,2)(B ?,2*(B ?,2+(B ?,2,(B ?,2-(B ?,2.(B ?,2/(B
  45.    ?,20(B ?,21(B ?,22(B ?,25(B ?,2~(B ?,2>(B ?,26(B ?,27(B ?,28(B ?,2v(B ?,2w(B ?,2o(B ?,2|(B ?,2{(B ?,2x(B ?,2O(B
  46.    ?,2u(B ?,1!(B ?,1"(B ?,1#(B ?,1$(B ?,1%(B ?,1&(B ?,1'(B ?,1((B ?,1)(B ?,1*(B ?,1+(B ?,1,(B ?,1-(B ?,1.(B ?,1/(B
  47.    ?,10(B ?,11(B ?,12(B ?,2^(B ?,2=(B ?,15(B ?,16(B ?,17(B ?,18(B ?,2q(B ?,2Q(B ?,2W(B ?,2X(B ?,1=(B ?,1>(B ?,2_(B
  48.    ?,2`(B ?,2a(B ?,2b(B ?,2c(B ?,2d(B ?,2e(B ?,1F(B ?,1G(B ?,2h(B ?,2i(B ?,2j(B ?,2k(B ?,2l(B ?,2m(B ?,2n(B ?,1O(B
  49.    ?,2p(B ?,1Q(B ?,2r(B ?,2s(B ?,2t(B ?,1U(B ?,1V(B ?,1W(B ?,1X(B ?,2y(B ?,2z(B ?,1[(B ?,1\(B ?,2}(B ?,1^(B ?,1_(B
  50.    ?,1`(B ?,1a(B ?,1b(B ?,1c(B ?,1d(B ?,1e(B ?,1f(B ?,1g(B ?,1h(B ?,1i(B ?,1j(B ?,1k(B ?,1l(B ?,1m(B ?,1n(B ?,1o(B
  51.    ?,1p(B ?,1q(B ?,1r(B ?,1s(B ?,1t(B ?,1u(B ?,1v(B ?,1w(B ?,1x(B ?,1y(B ?,1z(B ?,1{(B ?,1|(B ?,1}(B ?,1~(B ?,2f(B ]
  52.   "Vietnamese VISCII encoding table.")
  53.  
  54. (defvar viet-viscii-encode-table
  55.   (let ((table-lower (make-vector 128 0))
  56.     (table-upper (make-vector 128 0))
  57.     (i 0)
  58.     char-component)
  59.     (while (< i 256)
  60.       (setq char-component (split-char (aref viet-viscii-decode-table i)))
  61.       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
  62.          (aset table-lower (nth 1 char-component) i))
  63.         ((eq (car char-component) 'vietnamese-viscii-upper)
  64.          (aset table-upper (nth 1 char-component) i)))
  65.       (setq i (1+ i)))
  66.     (cons table-lower table-upper))
  67.   "Vietnamese VISCII decoding table.
  68. Cons of tables for decoding lower-case chars and upper-case characterss.
  69. Both tables are indexed by the position code of Vietnamese characters.")
  70.  
  71. (defvar viet-vscii-decode-table
  72.   [;; VSCII is a full 8-bit code.
  73.    0 ?,2z(B ?,2x(B 3 ?,2W(B ?,2X(B ?,2f(B 7 8 9 10 11 12 13 14 15
  74.    16 ?,2Q(B ?,2_(B ?,2O(B ?,2V(B ?,2[(B ?,2}(B ?,2\(B 24 25 26 27 28 29 30 31
  75.    32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  76.    48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  77.    64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  78.    80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  79.    96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
  80.    112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 
  81.    ?,2`(B ?,2d(B ?,2c(B ?,2a(B ?,2U(B ?,2#(B ?,2'(B ?,2h(B ?,2k(B ?,2((B ?,2i(B ?,2)(B ?,2.(B ?,2l(B ?,2o(B ?,2n(B
  82.    ?,2m(B ?,28(B ?,2r(B ?,2v(B ?,2u(B ?,2s(B ?,2w(B ?,25(B ?,26(B ?,27(B ?,2^(B ?,2>(B ?,2~(B ?,2y(B ?,2|(B ?,2{(B
  83.    160 ?,2e(B ?,2b(B ?,2j(B ?,2t(B ?,2=(B ?,2_(B ?,2p(B ?,1e(B ?,1b(B ?,1j(B ?,1t(B ?,1>(B ?,1y(B ?,1p(B ?,2"(B
  84.    192 193 194 195 196 ?,1`(B ?,1d(B ?,1c(B ?,1a(B ?,1U(B ?,2F(B ?,1"(B ?,1F(B ?,1G(B ?,1!(B ?,2G(B
  85.    ?,2!(B ?,2%(B ?,2&(B ?,2g(B ?,2%(B ?,2+(B ?,1#(B ?,1%(B ?,1&(B ?,1g(B ?,1$(B ?,1'(B ?,1h(B ?,2,(B ?,1k(B ?,1((B
  86.    ?,1i(B ?,1)(B ?,1+(B ?,1,(B ?,1-(B ?,1*(B ?,1.(B ?,1l(B ?,1o(B ?,2-(B ?,2*(B ?,20(B ?,1n(B ?,1m(B ?,18(B ?,1r(B
  87.    ?,21(B ?,1v(B ?,1u(B ?,1s(B ?,1w(B ?,10(B ?,11(B ?,12(B ?,1/(B ?,15(B ?,16(B ?,17(B ?,1^(B ?,1>(B ?,1~(B ?,1y(B
  88.    ?,22(B ?,1|(B ?,1{(B ?,1z(B ?,1x(B ?,1W(B ?,1X(B ?,1f(B ?,1Q(B ?,1q(B ?,1O(B ?,1V(B ?,1[(B ?,1}(B ?,1\(B ?,2/(B]
  89.   "Vietnamese VSCII code table.")
  90.  
  91. (defvar viet-vscii-encode-table
  92.   (let ((table-lower (make-vector 128 0))
  93.     (table-upper (make-vector 128 0))
  94.     (i 0)
  95.     char-component)
  96.     (while (< i 256)
  97.       (setq char-component (split-char (aref viet-vscii-decode-table i)))
  98.       (cond ((eq (car char-component) 'vietnamese-viscii-lower)
  99.          (aset table-lower (nth 1 char-component) i))
  100.         ((eq (car char-component) 'vietnamese-viscii-upper)
  101.          (aset table-upper (nth 1 char-component) i)))
  102.       (setq i (1+ i)))
  103.     (cons table-lower table-upper))
  104.   "Vietnamese VSCII decoding table.
  105. Cons of tables for decoding lower-case chars and upper-case characterss.
  106. Both tables are indexed by the position code of Vietnamese characters.")
  107.  
  108. )
  109.  
  110. (define-ccl-program ccl-read-viscii
  111.   `(((read r0)
  112.      (loop
  113.        (write-read-repeat r0 ,viet-viscii-decode-table))
  114.      ))
  115.   "CCL program to read VISCII 1.1")
  116.  
  117. ;; (define-ccl-program ccl-decode-viscii
  118. ;;   `(3
  119. ;;     ((read r0)
  120. ;;      (loop
  121. ;;       (write-read-repeat r0 ,viet-viscii-decode-table))
  122. ;;      ))
  123. ;;   "CCL program to decode VISCII 1.1")
  124.  
  125. ;; Multibyte form of a Vietnamese character is as follows (3-byte):
  126. ;;   LEADING-CODE-PRIVATE-11 LEADING-CODE-EXTENDED-11 POSITION-CODE
  127. ;; where LEADING-CODE-EXTENDED-11 for Vietnamese is
  128. ;; `vietnamese-viscii-lower' or `vietnamese-viscii-upper'.
  129.  
  130. (define-ccl-program ccl-write-viscii
  131.   `(((read r0)
  132.      (loop
  133.        (if (r0 < 128)
  134.        (write-read-repeat r0)
  135.      (if (r0 != 154)
  136.          (write-read-repeat r0)
  137.        ((read-if (r0 == 163)
  138.          ((read r0)
  139.           (r0 -= 160)
  140.           (write-read-repeat r0 ,(car viet-viscii-encode-table))
  141.           (if (r0 == 164)
  142.           ((read r0)
  143.            (r0 -= 160)
  144.            (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
  145.         (write-read-repeat r0))))))))))
  146.   "CCL program to write VISCII 1.1")
  147.  
  148. ;; (define-ccl-program ccl-encode-viscii
  149. ;;   `(1
  150. ;;      ((read r0)
  151. ;;       (loop
  152. ;;        (if (r0 < 128)
  153. ;;            ;; ASCII
  154. ;;            (write-read-repeat r0)
  155. ;;          ;; not ASCII
  156. ;;          (if (r0 != ,leading-code-private-11)
  157. ;;              ;; not Vietnamese
  158. ;;              (write-read-repeat r0)
  159. ;;            ((read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
  160. ;;              (;; Vietnamese lower
  161. ;;               (read r0)
  162. ;;               (r0 -= 128)
  163. ;;               (write-read-repeat r0 ,(car viet-viscii-encode-table)))
  164. ;;              (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
  165. ;;                  (;; Vietnamese upper
  166. ;;                   (read r0)
  167. ;;                   (r0 -= 128)
  168. ;;                   (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
  169. ;;                ;; not Vietnamese
  170. ;;                (write-read-repeat r0)))))))))
  171. ;;   "CCL program to encode VISCII 1.1")
  172.  
  173. (define-ccl-program ccl-vietnamese-lower-to-viscii
  174.   `(((r1 = r1
  175.      ,(car viet-viscii-encode-table))))
  176.   "CCL program to convert chars of 'vietnamese-lower to VISCII 1.1 font")
  177.  
  178. (define-ccl-program ccl-vietnamese-upper-to-viscii
  179.   `(((r1 = r1
  180.      ,(cdr viet-viscii-encode-table))))
  181.   "CCL program to convert chars of 'vietnamese-upper to VISCII 1.1 font")
  182.  
  183. ;; (define-ccl-program ccl-encode-viscii-font
  184. ;;   `(0
  185. ;;     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
  186. ;;     ;;      R1:position code
  187. ;;     ;; Out: R1:font code point
  188. ;;     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
  189. ;;         (r1 = r1 ,(car viet-viscii-encode-table))
  190. ;;       (r1 = r1 ,(cdr viet-viscii-encode-table)))
  191. ;;     )
  192. ;;   "CCL program to encode Vietnamese chars to VISCII 1.1 font")
  193.  
  194. (define-ccl-program ccl-read-vscii
  195.   `(((read r0)
  196.       (loop
  197.     (write-read-repeat r0 ,viet-vscii-decode-table))
  198.       ))
  199.   "CCL program to read VSCII-1.")
  200.  
  201. ;; (define-ccl-program ccl-decode-vscii
  202. ;;   `(3
  203. ;;     ((read r0)
  204. ;;      (loop
  205. ;;       (write-read-repeat r0 ,viet-vscii-decode-table))
  206. ;;      ))
  207. ;;   "CCL program to decode VSCII-1.")
  208.  
  209. (define-ccl-program ccl-write-vscii
  210.   `(((read r0)
  211.      (loop
  212.        (if (r0 < 128)
  213.        (write-read-repeat r0)
  214.      (if (r0 != 154)
  215.          (write-read-repeat r0)
  216.        (read-if (r0 == 163)
  217.             ((read r0)
  218.              (r0 -= 160)
  219.              (write-read-repeat r0 ,(car viet-vscii-encode-table)))
  220.             (if (r0 == 164)
  221.             ((read r0)
  222.              (r0 -= 160)
  223.              (write-read-repeat
  224.               r0 ,(cdr viet-viscii-encode-table)))
  225.               (write-read-repeat r0))))))))
  226.   "CCL program to write VSCII-1.")
  227.  
  228. ;; (define-ccl-program ccl-encode-vscii
  229. ;;   `(1
  230. ;;     ((read r0)
  231. ;;      (loop
  232. ;;       (if (r0 < 128)
  233. ;;           ;; ASCII
  234. ;;           (write-read-repeat r0)
  235. ;;         ;; not ASCII 
  236. ;;         (if (r0 != ,leading-code-private-11)
  237. ;;             ;; not Vietnamese
  238. ;;             (write-read-repeat r0)
  239. ;;           (read-if (r0 == ,(charset-id 'vietnamese-viscii-lower))
  240. ;;                    (;; Vietnamese lower
  241. ;;                     (read r0)
  242. ;;                     (r0 -= 128)
  243. ;;                     (write-read-repeat r0 ,(car viet-vscii-encode-table)))
  244. ;;                    (if (r0 == ,(charset-id 'vietnamese-viscii-upper))
  245. ;;                        (;; Vietnamese upper
  246. ;;                         (read r0)
  247. ;;                         (r0 -= 128)
  248. ;;                         (write-read-repeat r0 ,(cdr viet-viscii-encode-table)))
  249. ;;                      ;; not Vietnamese
  250. ;;                      (write-read-repeat r0))))))))
  251. ;;   "CCL program to encode VSCII-1.")
  252.  
  253. (define-ccl-program ccl-vietnamese-lower-to-vscii
  254.   '(((r1 = r1
  255.        [  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  256.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  257.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  258.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  259.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  260.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  261.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  262.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  263.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  264.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  265.       0 190 187 198 202 199 200 203 207 209 213 210 211 212 214 232
  266.     229 230 231   0   0 233 234 235 222   0   0   0   0   0 237   0
  267.       0   0   0   0   0   0 188 189   0   0   0   0   0   0   0 250
  268.       0 248   0   0   0 185 251 245 246   0   0 252 254   0 236   0
  269.     181 184 169 183 182 168 247 201 204 208 170 206 215 221 220 216
  270.     174 249 223 227 171 226 225 228 244 239 243 242 241 253 238   0
  271.     ])))
  272.   "CCL program to convert chars of 'vietnamese-lower to VSCII-1 font.")
  273.  
  274. (define-ccl-program ccl-vietnamese-upper-to-vscii
  275.   '(((r1 = r1
  276.        [  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  277.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  278.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  279.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  280.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  281.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  282.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  283.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  284.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  285.       0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
  286.       0 192 175 133   0 196 194 134 137 139 218 197 205 217 140 255
  287.     219 224 240   0   0 151 152 153 145   0   0   0   0 165 155   0
  288.       0   0   0   0   0   0 186 191   0   0   0   0   0   0   0  19
  289.       0  17   0   0   0 132  20   4   5   0   0  21  23   0 154 166
  290.     128 131 162 130 129 161   6 195 135 138 163 136 141 144 143 142
  291.     167   0 146 149 164 148 147 150   2 157   1 159 158  22 156   0
  292.     ])))
  293.   "CCL program to convert chars of 'vietnamese-upper to VSCII-1 font.")
  294.  
  295. ;; (define-ccl-program ccl-encode-vscii-font
  296. ;;   `(0
  297. ;;     ;; In:  R0:vietnamese-viscii-lower/vietnamese-viscii-upper
  298. ;;     ;;      R1:position code
  299. ;;     ;; Out: R1:font code point
  300. ;;     (if (r0 == ,(charset-id 'vietnamese-viscii-lower))
  301. ;;         (r1 = r1 ,(car viet-vscii-encode-table))
  302. ;;       (r1 = r1 ,(cdr viet-vscii-encode-table)))
  303. ;;     )
  304. ;;   "CCL program to encode Vietnamese chars to VSCII-1 font.")
  305.  
  306.  
  307. (make-coding-system
  308.  'viscii 'ccl
  309.  "Coding-system used for VISCII 1.1."
  310.  `(mnemonic "VISCII"
  311.    decode ,ccl-read-viscii
  312.    encode ,ccl-write-viscii))
  313.  
  314. ;; (make-coding-system
  315. ;;  'vietnamese-viscii 4 ?V
  316. ;;  "8-bit encoding for Vietnamese VISCII 1.1 (MIME:VISCII)"
  317. ;;  (cons ccl-decode-viscii ccl-encode-viscii))
  318.  
  319. ;; (define-coding-system-alias 'viscii 'vietnamese-viscii)
  320.  
  321. (make-coding-system
  322.  'vscii 'ccl
  323.  "Coding-system used for VSCII 1.1."
  324.  `(mnemonic "VSCII"
  325.    decode ,ccl-read-vscii
  326.    encode ,ccl-write-vscii))
  327.  
  328. ;; (make-coding-system
  329. ;;  'vietnamese-vscii 4 ?v
  330. ;;  "8-bit encoding for Vietnamese VSCII-1"
  331. ;;  (cons ccl-decode-vscii ccl-encode-vscii))
  332.  
  333. ;; (define-coding-system-alias 'vscii 'vietnamese-vscii)
  334.  
  335. (make-coding-system
  336.  'viqr 'no-conversion
  337.  "Coding-system used for VIQR."
  338.  '(mnemonic "VIQR"
  339.    eol-type lf
  340.    post-read-conversion viqr-post-read-conversion
  341.    pre-write-conversion viqr-pre-write-conversion))
  342.  
  343. ;; (make-coding-system
  344. ;;  'vietnamese-viqr 0 ?q
  345. ;;  "Vietnamese latin transcription (VIQR)"
  346. ;;  nil)
  347. ;; (put 'vietnamese-viqr 'post-read-conversion 'viqr-post-read-conversion)
  348. ;; (put 'vietnamese-viqr 'pre-write-conversion 'viqr-pre-write-conversion)
  349.  
  350. ;; (define-coding-system-alias 'viqr 'vietnamese-viqr)
  351.  
  352. ;; For VISCII users
  353. (set-charset-ccl-program 'vietnamese-viscii-lower
  354.              ccl-vietnamese-lower-to-viscii)
  355. (set-charset-ccl-program 'vietnamese-viscii-upper
  356.              ccl-vietnamese-upper-to-viscii)
  357. ;; For VSCII users
  358. ;; (set-charset-ccl-program 'vietnamese-lower ccl-vietnamese-lower-to-vscii)
  359. ;; (set-charset-ccl-program 'vietnamese-upper ccl-vietnamese-upper-to-vscii)
  360.  
  361. ;; (setq font-ccl-encoder-alist
  362. ;;       (cons (cons "viscii" ccl-encode-viscii-font) font-ccl-encoder-alist))
  363.  
  364. ;; (setq font-ccl-encoder-alist
  365. ;;       (cons (cons "vscii" ccl-encode-vscii-font) font-ccl-encoder-alist))
  366.  
  367. (set-language-info-alist
  368.  "Vietnamese" '((setup-function . setup-vietnamese-environment)
  369.         (charset . (vietnamese-viscii-lower
  370.                 vietnamese-viscii-upper))
  371.         (coding-system . (viscii vscii viqr))
  372.         (sample-text . "Vietnamese (Ti,1*(Bng Vi,1.(Bt)    Ch,1`(Bo b,1U(Bn")
  373.         (documentation . "\
  374. For Vietnamese, Emacs uses special charasets internally.
  375. They can be decoded from and encoded to VISCC, VSCII, and VIQR.")
  376.         ))
  377.  
  378. ;;; vietnamese.el ends here
  379.